package com.mostromas.ess.entities;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.google.common.collect.Lists;
import com.mostromas.ess.util.enums.SysUserType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="SysUser对象", description="用户信息表")
public class SysUser implements Serializable {
    private static final long serialVersionUID = -3056088096173790308L;
    @ApiModelProperty(value = "用户 ID")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private String id;

    @ApiModelProperty(value = "用户名")
    private String username;

    @JSONField(serialize = false) // 忽略转json
    @ApiModelProperty(value = "密码，加密存储, admin/1234")
    private String password;

    @ApiModelProperty(value = "帐户是否过期(1 未过期，0已过期)")
    private Integer isAccountNonExpired;

    @ApiModelProperty(value = "帐户是否被锁定(1 未过期，0已过期)")
    private Integer isAccountNonLocked;

    @ApiModelProperty(value = "密码是否过期(1 未过期，0已过期)")
    private Integer isCredentialsNonExpired;

    @ApiModelProperty(value = "帐户是否可用(1 可用，0 删除用户)")
    private Integer isEnabled;

    @ApiModelProperty(value = "昵称")
    private String nickName;

    @ApiModelProperty(value = "头像url")
    private String imageUrl;

    @ApiModelProperty(value = "注册手机号")
    private String mobile;

    @ApiModelProperty(value = "注册邮箱")
    private String email;

    @ApiModelProperty(value = "创建时间")
    private Date createDate;

    @ApiModelProperty(value = "更新时间")
    private Date updateDate;

    @ApiModelProperty(value = "密码更新时间")
    private Date pwdUpdateDate;

    @ApiModelProperty(value = "账户类型")
    private SysUserType userType = SysUserType.SYSTEM;

    @ApiModelProperty(value = "所属部门ID")
    private String departmentId;

    @TableField(exist = false)
    private SysDepartment department;
    //表示非数据库字段
    //@TableField(exist = false)
    // private Collection<? extends GrantedAuthority> authorities;

    /**
     * 用户所拥有的角色集合
     */
    @TableField(exist = false)
    private List<SysRole> roleList = Lists.newArrayList();

    /**
     * 获取所有的角色ID
     */
    @TableField(exist = false)
    private List<Long> roleIds = Lists.newArrayList();
    public List<Long> getRoleIds(){
        // if(CollectionUtils.isNotEmpty(roleList)){
        //     roleIds = Lists.newArrayList();
        //     for(SysRole role : roleList){
        //         roleIds.add(role.getId());
        //     }
        // }
        return roleIds;
    }

    /**
     * 用户所拥有的菜单资源
     */
    @TableField(exist = false)
    private List<SysMenu> permissions = Lists.newArrayList();
}
